package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.entity.Order;
import com.project.entity.OrderInfo;
import com.project.entity.PreOrder;
import com.project.entity.Product;
import com.project.mapper.OrderInfoMapper;
import com.project.mapper.OrderMapper;
import com.project.mapper.PreOrderMapper;
import com.project.mapper.ProductMapper;
import com.project.service.OrderInfoService;
import com.project.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    private PreOrderMapper preOrderMapper;

    @Autowired
    private OrderInfoMapper orderInfoMapper;

    @Override
    public void addPreOrder(Order order) {
        //按供应商ID查询采购信息表，得到入采购信息集合
        List<PreOrder> preOrderList = preOrderMapper.findByPreOrder(order.getFactoryId());
     //添加采购单
      order.setInDate(LocalDate.now().toString());   //获取当前时间
     this.baseMapper.insert(order);
     //添加采购单详情
     orderInfoMapper.addOrderInfoList(order.getOrderId(),preOrderList);
     //清空入库单
       QueryWrapper qw = new QueryWrapper<>();
       qw.eq("fk_userId",order.getUserId());
       qw.eq("fk_factoryId",order.getFactoryId());
       preOrderMapper.delete(qw);
    }

}
